﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout_lay_admin.cshtml";
}
<style>
    .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
        height: 34px;
        line-height: 34px;
        padding: 0 8px;
    }

    .layui-table-view {
    }

    .divborder {
        border-top: solid 1px #27AAA5;
        border-left: solid 1px #27AAA5;
        border-right: solid 1px #27AAA5;
    }

    .layui-btn-container .layui-btn {
        margin-bottom: 0px !important;
    }
</style>


<div class="layuimini-container">
    <div class="layuimini-main">
        @*<div class="layui-btn-group" style="padding-bottom:10px;">
                <button class="layui-btn" id="btn-add">添加</button>
            </div>*@
        <div class="layui-form layuimini-form">
            <div style="margin: 10px 10px 10px 10px">

                <div class="layui-inline ">
                    <label class="layui-form-label">职位名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keyword" id="keyword" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button id="btn-search" class="layui-btn " lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> @ViewBag.Search</button>
                </div>

            </div>
        </div>
        <div>
            @*<div class="layui-btn-group">
                    <button class="layui-btn" id="btn-expand">全部展开</button>
                    <button class="layui-btn layui-btn-normal" id="btn-fold">全部折叠</button>
                    <button class="layui-btn " id="btn-fresh">刷新</button>
                </div>*@
            <div class="layui-btn-container divborder" id="ex_btn" style=" padding-top:4px ; padding-bottom:4px ; padding-left:10px;">
                <button  ex_btn="ex_addCustomer"  class="layui-btn layui-btn-sm data-add-btn" id="btn-add"> @ViewBag.Add </button>
            </div>
            <table id="munu-table" class="layui-table" lay-filter="munu-table"></table>
            <!-- 操作列 -->
            <script type="text/html" id="auth-state">
                <a ex_btn="ex_add" class="layui-btn layui-btn-xs layui-btn-x" lay-event="add"> @ViewBag.AddChild </a>
                <a ex_btn="ex_edit" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">@ViewBag.Edit</a>
                <a ex_btn="ex_delete" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">@ViewBag.Delete</a>
            </script>
        </div>
    </div>

</div>

<script src="/Content/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script>
    var treetable;
    var reloadTable = function () {
        var keyword = $("#keyword").val();
        var _url = '/Base_Organization/Search' + "?keyword=" + keyword;

        // 渲染表格
        layer.load(2);
        treetable.render({
            treeColIndex: 1,
            treeSpid: '00000000-0000-0000-0000-000000000000',
            treeIdName: 'Organization_Id',
            treePidName: 'Organization_ParentId',
            elem: '#munu-table',
            url: _url,
            page: false,
            cols: [[
                { type: 'numbers' },
                { field: 'Organization_Name', minWidth: 200, title: '职位名称' },
                //{ field: 'authority', title: '权限标识' },
                //{ field: 'menuUrl', title: '菜单url' },
                { field: 'Organization_Sort', width: 80, align: 'center', title: '排序号' },
                //{
                //    field: 'Organization_Level', width: 80, align: 'center', templet: function (d) {
                //        if (d.isMenu == 1) {
                //            return '<span class="layui-badge layui-bg-gray">架构</span>';
                //        }
                //        if (d.parentId == -1) {
                //            return '<span class="layui-badge layui-bg-blue">架构</span>';
                //        } else {
                //            return '<span class="layui-badge-rim">架构</span>';
                //        }
                //    }, title: '类型'
                //},
                { templet: '#auth-state', width: 220, align: 'center', title: '操作' }
            ]],
            done: function () {
                layer.closeAll('loading');
            }
        });
    }

    layui.use(['table', 'treetable'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        window.treetable = layui.treetable;

        reloadTable();

        $('#btn-expand').click(function () {
            treetable.expandAll('#munu-table');
        });

        $('#btn-fold').click(function () {
            treetable.foldAll('#munu-table');
        });

        $("#btn-fresh").click(function () {
            reloadTable();
        });

        $("#btn-search").click(function () {
            reloadTable();
        });

        //监听工具条
        table.on('tool(munu-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'del') {
                layer.confirm('确定要禁用选中的账户吗？', function () {

                    $.ajax({
                        url: '/Base_Organization/ActivateSwich',
                        type: 'post',
                        dataType: 'text',
                        data: { "Ids": data.id },
                        success: function (resp) {
                            var json = eval('(' + resp + ')');
                            layer.alert(json.Message);
                            reloadTable();
                        },
                        error: function (resp) {
                            layer.alert("对不起出错了");
                        }
                    })
                })
            } else if (layEvent === 'edit') {
                var index = layer.open({
                    title: '修改组织',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['600px', '400px'],
                    content: '/Base_Organization/Edit?primarykey=' + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });


            } else if (layEvent === 'add') {

                var index = layer.open({
                    title: '添加组织',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['600px', '400px'],
                    content: '/Base_Organization/Create?parentid=' + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });

            }
        });

        $("#btn-add").click(function () {
            var index = layer.open({
                title: '添加新组织',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['600px', '400px'],
                content: '/Base_Organization/CreateCustom',
            });
            $(window).on("resize", function () {
                layer.full(index);
            });

        });
    });
</script>
